﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Practices.Unity;
using NeuralStock.DomainService.Interfaces;
using NeuralStock.DomainService;

namespace NeuralStock.Tests.Business
{
    [TestClass]
    public class CapEbitServiceTest
    {
        [TestMethod]
        public void CalculateCapEbit_Wawel2011_ShouldCalculateValidValues()
        {
            ICompanyService companyService = Bootstrapper.GetUnityContainer().Resolve<ICompanyService>();
            ICapEbitService capEbitService = Bootstrapper.GetUnityContainer().Resolve<ICapEbitService>();

            var companyId = companyService.Get("WAWEL").Id;

            var result = capEbitService.CalculateCapEbit(companyId, 2011, 2012, true);
            Assert.AreEqual(7.46346m, Math.Round(result.AvgCapEbitdaMinPrice, 5));
            Assert.AreEqual(-0.40770m, Math.Round(result.PotentialGrowthByMinPrice, 5));
        }

        [TestMethod]
        public void CalculateCapEbit_Wawel2010_ShouldCalculateValidValues()
        {
            ICompanyService companyService = Bootstrapper.GetUnityContainer().Resolve<ICompanyService>();
            ICapEbitService capEbitService = Bootstrapper.GetUnityContainer().Resolve<ICapEbitService>();

            var companyId = companyService.Get("WAWEL").Id;

            var result = capEbitService.CalculateCapEbit(companyId, 2010, 2011, true);
            Assert.AreEqual(-0.42756m, Math.Round(result.PotentialGrowthByMinPrice, 5));
        }

        [TestMethod]
        public void CalculateCapEbit_Wasko2011_ShouldCalculateValidValues()
        {
            ICompanyService companyService = Bootstrapper.GetUnityContainer().Resolve<ICompanyService>();
            ICapEbitService capEbitService = Bootstrapper.GetUnityContainer().Resolve<ICapEbitService>();

            var companyId = companyService.Get("WASKO").Id;

            var result = capEbitService.CalculateCapEbit(companyId, 2011, 2012, true);
            Assert.AreEqual(0.01402m, Math.Round(result.PotentialGrowthByMinPrice, 5));
        }

        [TestMethod]
        public void CalculateCapEbit_Wasko2013_ShouldCalculateValidValues()
        {
            ICompanyService companyService = Bootstrapper.GetUnityContainer().Resolve<ICompanyService>();
            ICapEbitService capEbitService = Bootstrapper.GetUnityContainer().Resolve<ICapEbitService>();

            var companyId = companyService.Get("WOJAS").Id;

            var result = capEbitService.CalculateCapEbit(companyId, 2012, 2013, false);
            Assert.AreEqual(-0.56917m, Math.Round(result.PotentialGrowthByMinPrice, 5));
            // test needs updating for last Quote value. It was written for day 2-09-2013
        }
    }
}
